{% extends "base.html" %}

{% block title %}发布动态 - {{ super() }}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card shadow-sm">
            <div class="card-header bg-primary text-white">
                <h4 class="mb-0">发布新动态</h4>
            </div>
            <div class="card-body">
                <form method="POST" enctype="multipart/form-data">
                    {{ form.hidden_tag() }}
                    <div class="mb-3">
                        {{ form.content.label(class="form-label") }}
                        {{ form.content(class="form-control", rows="5") }}
                        {% for error in form.content.errors %}
                            <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    <div class="mb-3">
                        {{ form.image.label(class="form-label") }}
                        {{ form.image(class="form-control") }}
                        {% for error in form.image.errors %}
                            <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                        <div class="form-text">支持 jpg、jpeg、png、gif 格式的图片</div>
                        <div class="mt-2">
                            <img id="imagePreview" src="#" alt="图片预览" style="max-width: 100%; max-height: 300px; display: none;">
                        </div>
                    </div>
                    <div class="d-grid gap-2">
                        {{ form.submit(class="btn btn-primary") }}
                        <a href="{{ url_for('main_bp_zc.index') }}" class="btn btn-outline-secondary">取消</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.getElementById('image').addEventListener('change', function(e) {
    const preview = document.getElementById('imagePreview');
    const file = e.target.files[0];
    
    if (file) {
        const reader = new FileReader();
        reader.onload = function(e) {
            preview.src = e.target.result;
            preview.style.display = 'block';
        }
        reader.readAsDataURL(file);
    } else {
        preview.style.display = 'none';
    }
});
</script>
{% endblock %} 